//
//  PersonViewController.m
//  Cheirapsis
//
//  Created by 潇湘妃子 on 15/11/16.
//  Copyright © 2015年 mohe. All rights reserved.
//

#import "PersonViewController.h"
#import "Define.h"
#import "AVUser.h"

@interface PersonViewController (){
    NSArray * arr;
    UIButton * donebtn;
    UIView * oneView;
    UILabel * nicheng;
    UILabel * xingbie;
    UILabel * xiaoxi;
    UITextField * nichengfield;
    UITextField * xingbiefield;
    UIButton * btnn;
 
}

@end

@implementation PersonViewController//<UITextFieldDelegate>
- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.separatorColor = [UIColor clearColor];
    self.title = @"个人设置";
    arr = @[
            @{
                @"title":@"昵       称:"
                },
            @{
                @"title":@"性       别:"
                },
            @{
                @"title":@"消息通知:"
                },
            @{
                @"title":@"退出登录"
                }
            ];
    [self write];
    
    AVUser * u = [AVUser currentUser];
    
    NSString *str = u[@"username"];
    // Do any additional setup after loading the view from its nib.
}
-(void)write{

    oneView = [[UIView alloc]initWithFrame:CGRectMake(0, 69, WIDTH, 1)];
    oneView.backgroundColor = [UIColor colorWithRed:242/255.0 green:242/255.0 blue:242/255.0 alpha:1.0];
    
    nicheng = [[UILabel alloc]initWithFrame:CGRectMake(92, 25, 80, 20)];
    nicheng.backgroundColor = [UIColor redColor];
    nicheng.font = [UIFont systemFontOfSize:10];
    nicheng.text = @"aaaaa";
    
    nichengfield= [[UITextField alloc]initWithFrame:CGRectMake(92, 25, 160, 30)];
    nichengfield.placeholder = @"请输入您的昵称";
  nichengfield.borderStyle = UITextBorderStyleRoundedRect;
  nichengfield.clearButtonMode = UITextFieldViewModeAlways;
    nichengfield.keyboardType = UIReturnKeyDone;
;


    
    
    donebtn= [[UIButton alloc]initWithFrame:CGRectMake(270, 25, 40, 15)];
    donebtn.backgroundColor = [UIColor grayColor];
    [donebtn setTitle:@"完成" forState:UIControlStateNormal];
    [donebtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [donebtn addTarget:self action:@selector(wancheng) forControlEvents:(UIControlEventTouchUpInside)];

 }
//两个点击事件，编辑和完成
-(void)bianji{
    
    nichengfield.hidden = NO;
    nicheng.hidden = YES;
    [btnn setTitle:@"wancheng" forState:UIControlStateNormal];

    nichengfield= [[UITextField alloc]initWithFrame:CGRectMake(92, 25, 180, 30)];
    nichengfield.placeholder = @"请输入您的昵称";
    nichengfield.borderStyle = UITextBorderStyleRoundedRect;
    nichengfield.clearButtonMode = UITextFieldViewModeAlways;
    nichengfield.returnKeyType =UIReturnKeyDefault;

}
-(void)wancheng{
    nicheng.hidden = NO;
    nichengfield.hidden = YES;
}

- (void)setNav{
    btnn = [[UIButton alloc]initWithFrame:CGRectMake(270, 25, 40, 15)];
    btnn.backgroundColor = [UIColor orangeColor];
    [btnn setTitle:@"编辑" forState:UIControlStateNormal];
    [btnn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [btnn addTarget:self action:@selector(bianji) forControlEvents:(UIControlEventTouchUpInside)];
    
}


//- (void)textFieldDidBeginEditing:(UITextField *)textField{
//   // nichengfield.delegate = self;
//    [nichengfield resignFirstResponder];
//    
//}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [nichengfield becomeFirstResponder];//主要是[receiver resignFirstResponder]在哪调用就能把receiver对应的键盘往下收
    
    return YES;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return arr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    NSDictionary *dic = [arr objectAtIndex:indexPath.row];
    cell.textLabel.text = dic[@"title"];
    if (indexPath.row==3) {
        cell.textLabel.textAlignment = NSTextAlignmentCenter;
        //cell.backgroundColor = [UIColor clearColor];
    }else{
        [self write];
        
        //页面隐藏textfield，“完成”button
        nichengfield.hidden= YES;
        donebtn.hidden = YES;
        btnn.tag = indexPath.row;
        


        //    oneView = [[UIView alloc]initWithFrame:CGRectMake(0, 69, WIDTH, 1)];
        //    oneView.backgroundColor = [UIColor colorWithRed:242/255.0 green:242/255.0 blue:242/255.0 alpha:1.0];
        [cell addSubview:nichengfield];
        [cell addSubview:nicheng];
        [cell addSubview:oneView];
        [cell addSubview:btnn];
        [cell addSubview:donebtn];

    }
      return cell;
}






- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 70;
}







- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
